package com.pacifictextiles.qc.inspection.server.model.test;

//defect.setRating(rs.getString(7).charAt(0));

import java.util.LinkedList;
import java.util.List;
import com.pacifictextiles.qc.inspection.server.model.dao.impl.DefectDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Defect;

public class testAddDefect {
	public static void main(String[] args) {

		// new an interface
		DefectDAOImpl testDefectDAOImpl = new DefectDAOImpl();

		// set instance variable of defect
		Defect defect = new Defect();
		defect.setIndexInRoll(4);
		defect.setRollNo("000000004");
		defect.setDefectCode(0);
		defect.setPosition(0);
		defect.setPoint(0);
		defect.setRating('A');

		// add OK
		try {
			testDefectDAOImpl.addDefect(defect);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// delete OK
		try {
			testDefectDAOImpl.deleteDefect("000000004", 4);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// get list
		try {
			List<Defect> defectList = new LinkedList<Defect>();

			//get by rollNO
			defectList = testDefectDAOImpl.getDefectList("500000001");
			printDefectList(defectList);
			
			// 判断有无查询到结果
			if (defectList.isEmpty()) {
				System.out.print("没有查询到 defect的信息" + "\n");
			}
		
		} catch (Exception e) {
			//e.printStackTrace();
			System.out.print("获取List失败"+"\n");
		}
	}// mian method

	private static void printDefectList(List<Defect> defectList)
			throws Exception {

		// count index of list
		int counterMinus = defectList.size() - 1;

		while (counterMinus >= 0) {
			Defect defect_receive = defectList.get(counterMinus);
			System.out.print(defect_receive.getIndexInRoll() + "\n"
					+ defect_receive.getRollNo() + "\n"
					+ defect_receive.getDefectCode() + "\n"
					+ defect_receive.getPosition() + "\n"
					+ defect_receive.getPoint() + "\n"
					+ defect_receive.getDateAndTime() + "\n" + "counter is:"
					+ counterMinus + "\n\n\n");
			counterMinus--;
		}
	}

}// public class
